from flask_marshmallow import base_fields

from flask_restplus_patched import Schema


class BaseResultSchema(Schema):
    status = base_fields.Boolean(
        description="The status of result, True meaning success and False meaning failure,default is True.",
        default=True, required=True)
    msg = base_fields.String(
        description="The message of result, it mean the error message when status equal True.")

    def _init__(self, status=True, message=None):
        self.status = status
        self.message = message


class Result(Schema):
    status = True
    message = None
    data = None

    def __init__(self, status=True, message=None, data=None):
        self.status = status
        self.message = message
        self.data = data

    def dict(self):
        return {'status': self.status, 'message': self.message, 'data': self.data}

    @classmethod
    def ok(self, message=None, data=None):
        return Result(True, message, data).dict();

    @classmethod
    def error(self, message):
        return Result(False, message, None).dict();
